#include "pch.h"
#include <assert.h>
#include "Delegate.h"

namespace MyPlayer
{
	int FileStreamRead(void* ptr, uint8_t* buf, int bufSize)
	{
		ReadDelegate^ readDelegate = reinterpret_cast<ReadDelegate^>(ptr);
		Platform::Array<byte>^ readedBytes = readDelegate(bufSize);
		if (readedBytes->Length == 0)
		{
			return AVERROR(EAGAIN);
		}
		assert(readedBytes->Length <= bufSize);
		memcpy_s(buf, bufSize, readedBytes->Data, readedBytes->Length);
		return readedBytes->Length;
	}
}